package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Resource
    private IServeService serveService;
    ;


    @GetMapping("/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page( ServePageQueryReqDTO dto) {
        return serveService.pageByDto(dto);
    }

    @PutMapping("/{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "regionId", value = "区域Id", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataType ="Double")
    })
    public void updateByPrice(@PathVariable Long id, @RequestParam Double price) {
            serveService.updatePrice(id,price);
    }

    @PostMapping("/batch")
    @ApiOperation("添加服务/批量")
    public void insertBatch(@RequestBody List<ServeResDTO> dtos) {
        serveService.batchServe(dtos);
    }

    @PutMapping("/onSale/{itemId}")
    @ApiOperation("修改服务的状态/上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "itemId",value = "服务项id",required = true)
    })
    public void updateByServeIdUp(@PathVariable Long itemId) {
        serveService.updateByItemId(itemId);
    }

    @PutMapping("/offSale/{serveId}")
    @ApiOperation("修改服务的状态/下架")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId",value = "区域服务id",required = true)
    })
    public void updateByServeIdDo(@PathVariable Long serveId) {
        serveService.updateByServeDo(serveId);
    }

    @DeleteMapping("/{serveId}")
    @ApiOperation("删除服务项目")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId",value = "区域服务id",required = true)
    })
    public void deleteByServeId(@PathVariable Long serveId) {
        serveService.deleteByServeId(serveId);
    }

    @PutMapping("/onHot/{serveId}")
    @ApiOperation("设置服务项目热门状态/是")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId",value = "区域服务id",required = true)
    })
    public void updateByServeIdHot(@PathVariable Long serveId) {
        serveService.updateServeHotUp(serveId);
    }

    @PutMapping("/offHot/{serveId}")
    @ApiOperation("设置服务项目热门状态/否")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "serveId",value = "区域服务id",required = true)
    })
    public void updateByServeIdHotDo(@PathVariable Long serveId) {
        serveService.updateServeHotDo(serveId);
    }
}
